<template>
  <div v-if="value" class="modal-warpper">
    <div class="modal">
      <div class="modal-header">
        <slot name="header">{{header}}</slot>
        <span class="close" @click="cancel">&times;</span>
      </div>
      <div class="modal-content">
        <slot></slot>
      </div>
      <div class="modal-footer">
        <slot name="footer">
          <button class="btn" @click="cancel">取消</button>
          <button class="btn" @click="confirm">确认</button>
        </slot>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    value: Boolean,
    header: String,
    footer: String,
  },
  methods: {
    cancel() {
      this.$emit('input', false);
      this.$emit('cancel');
    },
    confirm() {
      this.$emit('input', false);
      this.$emit('confirm');
    },
  },
};
</script>

<style lang="less">
.modal-warpper {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: rgba(0, 0, 0, .5);
  .modal {
    background-color: #fff;
    border-radius: 5px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    .modal-header {
      position: relative;
      padding: 10px 20px;
      .close {
        position: absolute;
        right: 5px;
        top: 5px;
        font-size: 24px;
        cursor: pointer;
      }
    }
    .modal-content {
      padding: 20px;
    }
    .modal-footer {
      padding: 10px 20px;
      white-space: nowrap;
    }
  }
}
</style>
